package com.example.apitesttool;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 大模型驱动的自动化接口测试工具主应用类
 * 
 * 功能特性：
 * - OpenAPI/Swagger 文档上传与解析
 * - 对话式测试定义与执行
 * - 大模型驱动的智能测试用例生成
 * - HTTP 请求执行与结果分析
 * 
 * @author liuxy
 * @version 1.0.0
 */
@SpringBootApplication
public class ApiTestToolApplication {

    public static void main(String[] args) {
        SpringApplication.run(ApiTestToolApplication.class, args);
        System.out.println("=== API Test Tool 启动成功 ===");
        System.out.println("访问地址: http://localhost:8080");
        System.out.println("上传接口: POST /api/swagger/upload");
        System.out.println("聊天接口: POST /api/chat/message");
    }

    /**
     * 配置 CORS 以支持前端跨域请求
     */
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/api/**")
                        .allowedOrigins("*")
                        .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                        .allowedHeaders("*")
                        .allowCredentials(false);
            }
        };
    }
}

